function v2d_images(fbase, range)
%
%  function v2d_images(fbase, range)
%
%  Reads text files with 2D data and creates images.
%
%      fbase :  string with file name base (without *.dat extension)
%      range :  vector (min, max) for colormap scaling
%


%----------------------------------------------------------

    f = importdata([fbase, '.dat']);

    x = f(1,:);
    y = f(:,1);

    f = f(2:end, 2:end);

    fmax = max(max(f));
    fmin = min(min(f));

    fprintf('data range = [ %f, %f]\n', fmin, fmax);
    fprintf('used range = [ %f, %f]\n', range(1), range(2));

    f = flipud(f);

    imagesc(f);
 
    one_image(f, range(1), range(2), [fbase, '.png']);

end


%---------------------------------------------------------

function one_image(a, amin, amax, fname)

  a = max(a,amin);
  a = min(a,amax); 

  map = colormap(jet(256));

  sc   =  uint8(255*(a-amin)/(amax-amin)) + 1;
  imwrite(sc, map, fname);

end


%---------------------------------------------------------
